package com.igeek.car.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.car.constant.MessageConstant;
import com.igeek.car.entity.Reschedules;
import com.igeek.car.result.Result;
import com.igeek.car.service.ReschedulesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import com.igeek.car.vo.PageQueryVO;
import org.springframework.web.bind.annotation.*;

/**
 * ReschedulesController 改签记录接口，仅仅只做接口暴露
 * ReschedulesService   改签记录业务
 *      ReschedulesServiceImpl  改签记录业务的具体实现
 * ReschedulesMapper   改签记录的持久层交互
 *
 * Swagger测试地址：http://localhost:8080/swagger-ui.html
 *
 * @author Suzi
 * @since 2024-12-05
 */
@RestController
@RequestMapping("/admin/reschedules")
@Api(tags = "改签记录的接口管理")
public class ReschedulesController {

    @Autowired
    private ReschedulesService reschedulesService;

    @ApiOperation("分页条件查询改签记录")
    @GetMapping("findPage")
    public Result findPage(PageQueryVO vo){
        Page<Reschedules> page = reschedulesService.findPage(vo);
        if(page != null){
            return new Result(true, MessageConstant.QUERY_RESCHEDULE_SUCCESS, page);
        }
        return new Result(false, MessageConstant.QUERY_RESCHEDULE_FAIL);
    }

    @ApiOperation("新增改签记录")
    @PostMapping("add")
    public Result add(@RequestBody Reschedules reschedules){
        boolean flag = reschedulesService.save(reschedules);
        if(flag){
            return new Result(true, MessageConstant.ADD_RESCHEDULE_SUCCESS);
        }
        return new Result(false, MessageConstant.ADD_RESCHEDULE_FAIL);
    }

    @ApiOperation("通过ID查询改签记录信息")
    @GetMapping("{id}")
    public Result findOne(@PathVariable("id") Integer id){
        Reschedules reschedules = reschedulesService.getById(id);
        if(reschedules != null){
            return new Result(true, MessageConstant.QUERY_RESCHEDULE_SUCCESS, reschedules);
        }
        return new Result(false, MessageConstant.QUERY_RESCHEDULE_FAIL);
    }

    @ApiOperation("编辑改签记录")
    @PutMapping("update")
    public Result update(@RequestBody Reschedules reschedules){
        boolean flag = reschedulesService.updateById(reschedules);
        if(flag){
            return new Result(true, MessageConstant.UPDATE_RESCHEDULE_SUCCESS);
        }
        return new Result(false, MessageConstant.UPDATE_RESCHEDULE_FAIL);
    }

    @ApiOperation("删除改签记录")
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        boolean flag = reschedulesService.del(id);
        if(flag){
            return new Result(true, MessageConstant.DELETE_RESCHEDULE_SUCCESS);
        }
        return new Result(false, MessageConstant.DELETE_RESCHEDULE_FAIL);
    }
}